class Solution(object):
    def queensAttacktheKing(self, queens, king):
        queens = {tuple(q) for q in queens}
        out = []
        now = [(-1, 0), (1, 0), (0, -1), (0, 1), (-1, -1), (-1, 1), (1, -1), (1, 1)]
        dist = 0
        while now:
            dist += 1
            next_list = []
            for node in now:
                next_node = (king[0] + dist * node[0], king[1] + dist * node[1])
                if 0 <= next_node[0] < 8 and 0 <= next_node[1] < 8:
                    if next_node in queens:
                        out.append(list(next_node))
                    else:
                        next_list.append(node)
            now = next_list
        return out

